package cn.tedu.voice.system.controller;

import cn.tedu.voice.system.mvc.JsonResult;
import cn.tedu.voice.system.pojo.dto.UserLoginDTO;
import cn.tedu.voice.system.pojo.vo.UserVO;
import cn.tedu.voice.system.service.ILoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "1.用户登录模块")
@Validated
public class LoginController {

    @Autowired
    private ILoginService loginService;

    @PostMapping("/add-new")
    @ApiOperation("添加用户")
    public JsonResult<Void> addNew(@Valid UserLoginDTO userLoginDTO) {
        log.debug("开始处理添加用户");
        loginService.addNew(userLoginDTO);
        return JsonResult.ok();
    }

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public JsonResult<Void> getUsername(HttpSession session, @RequestBody @Valid UserLoginDTO userLoginDTO) {
        log.debug("用户登录,参数：{}", userLoginDTO);
        loginService.login(session,userLoginDTO);
        return JsonResult.ok();
    }


}
